/*
 * @Author: zheng yong tao
 * @Date: 2022-01-15 23:22:04
 * @LastEditors: zheng yong tao
 * @LastEditTime: 2022-03-03 22:23:32
 * @Description:
 */
import Vue from "vue";
import VueResource from "vue-resource";
import { requestLog, responseLog } from "../util/console";
Vue.use(VueResource);
export class myHttp {
  constructor(_this) {
    this.that = _this;
  }
  async httpGet(path, params) {
    location.href.startsWith("http://localhost")
      ? requestLog("request-get", path.split("/").pop(), params)
      : "";
    let res = await this.$http.get(
      path,
      { params: params },
      { emulateJSON: true }
    );
    location.href.startsWith("http://localhost")
      ? responseLog("response-get", path.split("/").pop(), res.body)
      : "";
    return Promise.resolve(res.body);
  }
  async httpPost(path, params) {
    location.href.startsWith("http://localhost")
      ? requestLog("request-post", path.split("/").pop(), params)
      : "";
    let res = await this.$http.post(path, params, { emulateJSON: true });
    location.href.startsWith("http://localhost")
      ? responseLog("response-post", path.split("/").pop(), res.body)
      : "";
    return Promise.resolve(res.body);
  }
}
